<template>
    <div style="position: relative;">
      <el-form ref="SpecialCheckListFilter" :model="SpecialCheckList" :size="defaultFormItemSize"
        label-width="100px" label-position="right" @submit.native.prevent>
        <filter-box :item-width="350">
          <el-form-item label="项目" prop="formFilter.proId">
            <el-select class="filter-item"
                       v-model="SpecialCheckList.formFilter.proId"
                       :clearable="true"
                       filterable
                       placeholder="项目"
                       :loading="SpecialCheckList.projectId.impl.loading"
                       @visible-change="SpecialCheckList.projectId.impl.onVisibleChange"
                       @change="onProjectIdValueChange">
                <el-option v-for="item in SpecialCheckList.projectId.impl.dropdownList"
                           :key="item.id" :value="item.id" :label="item.name"/>
            </el-select>
          </el-form-item>
          <el-button slot="operator" type="default" :plain="true" :size="defaultFormItemSize"
                     @click="onResetSpecialCheckList">重置</el-button>
          <el-button slot="operator" type="default" :plain="true" :size="defaultFormItemSize"
                     @click="refreshSpecialCheckList(true)">查询</el-button>
          <el-button slot="operator" type="default" :plain="true" :size="defaultFormItemSize"
                     @click="onSpecialCheckFormClick">新增</el-button>
        </filter-box>
      </el-form>
      <el-row>
        <el-col :span="24">
          <el-table ref="specialCheck" :data="SpecialCheckList.SpecialCheck.impl.dataList" :size="defaultFormItemSize"
                    @sort-change="SpecialCheckList.SpecialCheck.impl.onSortChange"
                    header-cell-class-name="table-header-gray">
            <el-table-column label="序号" header-align="center" align="center" type="index"
                             width="55px" :index="SpecialCheckList.SpecialCheck.impl.getTableIndex">
            </el-table-column>
            <el-table-column label="项目" prop="projectIdDictMap.name"></el-table-column>
            <el-table-column label="合同" prop="contractIdDictMap.name"></el-table-column>
            <el-table-column label="检查描述" prop="checkDescribe"></el-table-column>
            <el-table-column label="检查报告" prop="checkReport"></el-table-column>
            <el-table-column label="整改状态" prop="changeStausDictMap.name"></el-table-column>
            <el-table-column label="检测单位" prop="checkOrgTypeDictMap.name"></el-table-column>
            <el-table-column label="填报日期" prop="addTime"></el-table-column>
            <el-table-column label="操作" fixed="right">
              <template slot-scope="scope">
                <el-button @click.stop="onSpecialCheckFormEditClick(scope.row)" type="text"
                           :size="defaultFormItemSize">编辑</el-button>
                <el-button @click.stop="onDeleteClick(scope.row)" type="text" :size="defaultFormItemSize">
                  删除
                </el-button>
              </template>
            </el-table-column>
          </el-table>
          <el-row type="flex" justify="end" style="margin-top: 10px;">
            <el-pagination
              :total="SpecialCheckList.SpecialCheck.impl.totalCount"
              :current-page="SpecialCheckList.SpecialCheck.impl.currentPage"
              :page-size="SpecialCheckList.SpecialCheck.impl.pageSize"
              :page-sizes="[10, 20, 50, 100]"
              layout="total, prev, pager, next, sizes"
              @current-change="SpecialCheckList.SpecialCheck.impl.onCurrentPageChange"
              @size-change="SpecialCheckList.SpecialCheck.impl.onPageSizeChange">
            </el-pagination>
          </el-row>
        </el-col>
      </el-row>
    </div>
</template>

<script>
  import { findTreeNode, findTreeNodePath, findItemFromList } from '@/utils';
  import { DropdownWidget, TableWidget, UploadWidget, ChartWidget } from '@/utils/widget.js';
  import { uploadMixin, statsDateRangeMixin, cachePageMixin } from '@/core/mixins';
  import { SpecialCheckController, DictionaryController } from '@/api';
  import specialCheckForm from '@/views/myOrg/specialCheckForm.vue';

    export default {
        name: "specialCheckList",
      props: {
      },
      mixins: [uploadMixin, statsDateRangeMixin, cachePageMixin],
      data () {
        return {
          SpecialCheckList: {
            formFilter: {
              proId: undefined,
              sectionId: undefined,
              checkDescribe: undefined,
              checkReport: undefined,
              changeStaus: undefined,
              addTime:undefined,
              checkOrgType: undefined
            },
            formFilterCopy: {
              proId: undefined,
              sectionId: undefined,
              checkDescribe: undefined,
              checkReport: undefined,
              changeStaus: undefined,
              addTime:undefined,
              checkOrgType: undefined
            },
            SpecialCheck: {
              impl: new TableWidget(this.loadSpecialCheckWidgetData, this.loadSpecialCheckVerify, true, false, 'addTime', 0)
            },
            projectId: {
              impl: new DropdownWidget(this.loadProjectIdDropdownList),
            },
            isInit: false
          }
        }
      },
      methods: {
          onResetSpecialCheckList () {
            this.$refs.SpecialCheckListFilter.resetFields();
            this.refreshSpecialCheckList(true);
          },
        /**
         * 数据获取函数，返回Promise
         */
        loadSpecialCheckWidgetData (params) {
          if (params == null) params = {};
          params = {
            ...params,
            specialCheckDtoFilter: {
              proId: this.SpecialCheckList.formFilterCopy.proId,
              sectionId: this.SpecialCheckList.formFilterCopy.sectionId,
              checkDescribe: this.SpecialCheckList.formFilterCopy.checkDescribe,
              checkReport: this.SpecialCheckList.formFilterCopy.checkReport,
              changeStaus: this.SpecialCheckList.formFilterCopy.changeStaus,
              checkOrgType: this.SpecialCheckList.formFilterCopy.checkOrgType
            }
          };
          return new Promise((resolve, reject) => {
            SpecialCheckController.list(this, params).then(res => {
              resolve({
                dataList: res.data.dataList,
                totalCount: res.data.totalCount
              });
            }).catch(e => {
              reject(e);
            });
          });
        },
        /**
         * 项目id下拉数据获取函数
         */
        loadProjectIdDropdownList () {
          return new Promise((resolve, reject) => {
            let params = {};
            DictionaryController.dictSysProject(this, params).then(res => {
              resolve(res.getList());
            }).catch(e => {
              reject(e);
            });
          });
        },
        /**
         * 数据获取检测函数，返回true正常获取数据，返回false停止获取数据
         */
        loadSpecialCheckVerify () {
          this.SpecialCheckList.formFilterCopy.proId = this.SpecialCheckList.formFilter.proId;
          this.SpecialCheckList.formFilterCopy.sectionId = this.SpecialCheckList.formFilter.sectionId;
          this.SpecialCheckList.formFilterCopy.checkDescribe = this.SpecialCheckList.formFilter.name;
          this.SpecialCheckList.formFilterCopy.checkReport = this.SpecialCheckList.formFilter.checkReport;
          this.SpecialCheckList.formFilterCopy.changeStaus = this.SpecialCheckList.formFilter.changeStaus;
          this.SpecialCheckList.formFilterCopy.checkOrgType = this.SpecialCheckList.formFilter.checkOrgType;
          return true;
        },
        /**
         * 更新表页
         */
        refreshSpecialCheckList (reloadData = false) {
          if (reloadData) {
            this.SpecialCheckList.SpecialCheck.impl.refreshTable(true, 1);
          } else {
            this.SpecialCheckList.SpecialCheck.impl.refreshTable();
          }
          if (!this.SpecialCheckList.isInit) {
            // 初始化下拉数据
          }
          this.SpecialCheckList.isInit = true;
        },
        /**
         * 新增
         */
        onSpecialCheckFormClick () {
          let params = {};
          this.$dialog.show('新增',specialCheckForm, {
            area: '800px'
          },params).then(res => {
            this.refreshSpecialCheckList();
          }).catch(e => {});
        },
        /**
         * 编辑
         */
        onSpecialCheckFormEditClick (row) {
          let params = {
            id: row.specialCheckId
          };
          this.$dialog.show('编辑',specialCheckForm, {
            area: '800px'
          },params).then(res => {
            this.SpecialCheckList.SpecialCheck.impl.refreshTable();
          }).catch(e => {});
        },
        /**
         * 删除
         */
        onDeleteClick (row) {
          let params = {
            id : row.specialCheckId
          };
          SpecialCheckController.delete(this,params).then(res => {
            this.$message.success('删除成功');
            this.SpecialCheckList.SpecialCheck.impl.refreshTable(false,1);
          }).catch(e => {});
        },
        /**
         * 选中值改变
         */
        onProjectIdValueChange (value) {
          this.formData.SpecialCheck.sectionId = undefined;
          this.SpecialCheckList.contractId.impl.dirty = true;
          this.onContractIdValueChange(this.formData.SpecialCheck.sectionId);
        },
        onResume () {
          this.refreshSpecialCheckList();
        },
        initFormData () {

        },
        formInit () {
          this.refreshSpecialCheckList();
        }
      },
      mounted () {
          this.formInit();
      },
      watch: {}
    }
</script>

<style scoped>

</style>
